package com.qzsoft.zhjd.machine.modules.machinereport.dto;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.List;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.ToString;

/**
 * @ClassName MachineReportIntactRateDto
 * @Description 设备完好率
 * @author linhuawei
 * @since 2021-11-04
 */
@Data
@EqualsAndHashCode(callSuper = false)
@NoArgsConstructor
@AllArgsConstructor
@Builder
@ToString
public class MachineReportIntactRateDto {

    /**
     * 机构主键
     */
    private String deptPkid;

    /**
     * 机构编码
     */
    private String deptId;

    /**
     * 机构名称
     */
    private String deptName;
    
    /**
     * 设备总数
     */
    private Integer count;

    /**
     * 完好
     */
    private Integer intact;

    /**
     * 基本完好
     */
    private Integer basicIntact;

    /**
     * 状况一般
     */
    private Integer normal;

    /**
     * 待维修
     */
    private Integer repaired;

    /**
     * 待报废
     */
    private Integer scrapped;
    
    /**
     * 完好率
     */
    private BigDecimal intactRate;

    /**
     * 下级机构汇总信息
     */
    private List<MachineReportIntactRateDto> list;
    
    public Integer getCount() {
        if(null == count) {
            Integer sum = 0;
            sum += null == intact ? 0 : intact;
            sum += null == basicIntact ? 0 : basicIntact;
            sum += null == normal ? 0 : normal;
            sum += null == repaired ? 0 : repaired;
            sum += null == scrapped ? 0 : scrapped;
            count = sum;
        }
        return count;
    }
    
    public BigDecimal getIntactRate() {
        if(null == intactRate) {
            Integer count = getCount();
            if(0 == count) {
                intactRate = new BigDecimal(1);
            } else {
                Integer sum = 0;
                sum += null == intact ? 0 : intact;
                sum += null == basicIntact ? 0 : basicIntact;
                sum += null == normal ? 0 : normal;
                intactRate = new BigDecimal(sum).divide(new BigDecimal(count), 4, RoundingMode.DOWN);
            }
        }
        return intactRate;
    }

}
